package com.school.hjt.schoolclasscard.ui

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.WindowManager
import android.webkit.WebSettings

import com.school.hjt.schoolclasscard.R
import kotlinx.android.synthetic.main.activity_dong.*


class DongActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar!!.hide()
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
        window.setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
        setContentView(R.layout.activity_dong)
        val web = intent.getStringExtra("web")
        val title = intent.getStringExtra("title")
        tv_dong_name.text=title
        Log.e("MyUncaughtHandler",web)
        web_dong.settings.useWideViewPort = true
        web_dong.settings.javaScriptEnabled = true
        //不使用缓存：
        web_dong.settings.cacheMode = WebSettings.LOAD_NO_CACHE
        web_dong.settings.setSupportZoom(true) //设置可以支持缩放
        web_dong.settings.defaultZoom = WebSettings.ZoomDensity.FAR
        web_dong.loadUrl(web)
        Thread(Runnable {
            while (i > 0) {
                handler.sendEmptyMessage(1)
                if (i <= 0) {
                    break
                }
                try {
                    Thread.sleep(1000)
                } catch (e:InterruptedException) {
                    e.printStackTrace()
                }
                i--
            }
            handler.sendEmptyMessage(2)
        }).start()
        iv_dong_close.setOnClickListener({
            finish()
        })
    }
    internal var i = 30
    private var handler: Handler = object : Handler() {
        override fun handleMessage(msg: android.os.Message) {
            if (msg.what == 1) {
                tv_dong_countdown1.text="还剩" + i + "关闭界面"
            } else {
                finish()
            }
        }
    }
}
